//
//  LoginPassInputViewCell.m
//  OfficeBook
//
//  Created by 朱 琳 on 15/10/11.
//  Copyright (c) 2015年 sunny. All rights reserved.
//

#import "LoginPasswordViewCell.h"

NSInteger LoginPasswordCellTextFieldTag = 2000;

@interface LoginPasswordViewCell()<UITextFieldDelegate>

@property (nonatomic, strong) UIImageView *iconImageView;
@property (nonatomic, strong) UITextField *contentTextField;
@property (nonatomic, strong) UIButton    *forgetPwdBtn;

@end

@implementation LoginPasswordViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    
    self.iconImageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"passwdIcon"]];
    self.contentTextField = [[UITextField alloc]init];
    self.forgetPwdBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    
    self.contentTextField.secureTextEntry = YES;
    self.contentTextField.placeholder = @"Enter Password";
    self.contentTextField.font = [UIFont systemFontOfSize:15];
    self.contentTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
    self.contentTextField.keyboardType = UIKeyboardTypeDefault;
    self.contentTextField.delegate = self;
    self.contentTextField.tag = LoginPasswordCellTextFieldTag;
    
    [self.forgetPwdBtn setTitle:@"Forgot Password?" forState:UIControlStateNormal];
    [self.forgetPwdBtn setTitleColor:[UIColor colorWithHexString:@"6d6d6d"] forState:UIControlStateNormal];
    [self.forgetPwdBtn.titleLabel setFont:[UIFont systemFontOfSize:13]];
    [self.forgetPwdBtn addTarget:self action:@selector(handleForgetBtn:) forControlEvents:UIControlEventTouchUpInside];
    
    [self.contentView addSubview:self.iconImageView];
    [self.contentView addSubview:self.contentTextField];
    [self.contentView addSubview:self.forgetPwdBtn];
    
    [self.iconImageView makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.leftMargin);
        make.centerY.equalTo(self.contentView.centerY);
        make.width.equalTo(@25);
        make.height.equalTo(@25);
    }];

    [self.forgetPwdBtn makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.contentView.rightMargin);
        make.centerY.equalTo(self.contentView.centerY);
        make.width.equalTo(@120);
        make.height.equalTo(@22);
    }];
    
    [self.contentTextField makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.iconImageView.right).offset(15);
        make.right.equalTo(self.forgetPwdBtn.left);
        make.centerY.equalTo(self.contentView.centerY);
        make.height.equalTo(@44);
    }];
    
    return self;
}

-(void)handleForgetBtn:(id)sender {
    
}

@synthesize password = _password;
-(void)setPassword:(NSString *)password {
    _password = password;
    self.contentTextField.text = password;
}

-(NSString *)password {
    _password = self.contentTextField.text;
    return _password;
}

#pragma mark UITextField delegate
-(BOOL)textFieldShouldReturn:(UITextField *)textField{
    [self.contentTextField resignFirstResponder];
    return YES;
}
@end
